package com.jz.community.modulemine.information.task;

import android.app.Activity;

import com.alibaba.fastjson.JSON;
import com.jz.community.basecomm.constant.AppConstants;
import com.jz.community.basecomm.constant.Constant;
import com.jz.community.basecomm.net.OkHttpUtil;
import com.jz.community.basecomm.task.ITaskCallbackListener;
import com.jz.community.basecomm.task.RxTask;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.modulemine.information.bean.SpecialCouponBean;

import java.util.HashMap;

public class SpecialCouponTask extends RxTask<String, Integer, SpecialCouponBean> {


    private Activity activity;
    private ITaskCallbackListener taskListener;

    public SpecialCouponTask(Activity activity, ITaskCallbackListener taskListener) {
        super(activity);
        this.activity = activity;
        this.taskListener = taskListener;
    }

    @Override
    protected SpecialCouponBean doInBackground(String... strings) {
        String result = OkHttpUtil.get(Constant.SPECIAL_COUPON_URL, getParam());
        SpecialCouponBean bean = null;
        if (!Preconditions.isNullOrEmpty(result)) {
            bean = JSON.parseObject(result, SpecialCouponBean.class);
        }
        return bean;
    }

    @Override
    protected void onPostExecute(SpecialCouponBean result) {
        // 执行结果回调函数
        taskListener.doTaskComplete(result);
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }


    private HashMap<String, Object> getParam() {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("app-code", AppConstants.APPID);
        return hashMap;
    }
}
